package zisu.algorithm.algorithm.Queue;

import zisu.algorithm.algorithm.Array.Array;

/**
 * @Author: 蔡翔
 * @Date: 2019/12/3 13:34
 * @Version 1.0
 */
public class ArrayQueue<E> implements Queue<E> {

    private Array<E> array;

    public ArrayQueue(int capacity){
        array = new Array<>(capacity);
    }

    public ArrayQueue(){
        array = new Array<>();
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }



    @Override
    public void enQueue(E e) {
        array.addLast(e);
    }

    @Override
    public E deQueue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }

    @Override
    public Integer getCapacity() {
        return array.getCapacity();
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Queue:");
        stringBuilder.append("Front [");
        for (int i = 0 ;i<array.getSize();i++){
            stringBuilder.append(array.get(i));
            if(i!= (array.getSize()-1)){
                stringBuilder.append(",");
            }
        }
        stringBuilder.append("] tail");
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        for(int i = 0;i<10;i++){
            arrayQueue.enQueue(i);
            System.out.println("enqueue:"+i);
        }
        System.out.println(arrayQueue.toString());
    }
}
